/**   
 * @Title: LotteryInfoListFootball.java 
 * @Package: com.esun.rabbit2.viewer.mainact.lotteryinfoact 
 * @Description: (竞彩足球赛果查询列表) 
 * @Author: hxt 
 * @date create at 2012-5-9 下午4:15:03
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */

package com.esun.cheetah.view.personal.sportlotteryfootball;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Hashtable;

import android.app.Activity;
import android.app.ProgressDialog;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.esun.cheetah.R;
import com.esun.cheetah.biz.personal.lotteryrecord.FootballLotteryInfoCommunicater;

import com.esun.cheetah.config.Config;
import com.esun.cheetah.config.Language;
import com.esun.cheetah.network.ConnectionChangeReceiver;

import com.esun.util.ViewerUtil;
import com.esun.util.log.EDebug;

/**
 * 
 * @Package com.esun.cheetah.view.personal.sportlotteryfootball.LotteryInfoListFootball
 * @ClassName: LotteryInfoListFootball
 * @Description: TODO(lottery list info activity)
 * @author handy <br/>
 * @date create at 2012-7-31 下午2:49:30
 *
 */
public class LotteryInfoListFootball extends Activity implements
		OnScrollListener, android.view.View.OnClickListener {

	private ExpandableListView expandListView;
	private TextView tvFail;
	private TextView tvTipDate;
	private TextView tvTipWeek;
	private Button backbtnButton;
	private TextView tvTipCount;
	private RelativeLayout relativeTipTop;
	private ImageView imgTipTop;
	private LotteryInfoExpendsAdapter expandListAdapter;
	public static Handler handler;
//	private Bundle bundle;
	private String lotid = "";
	private String expectSelected = "";
	private static FootballLotteryInfoCommunicater communicater;
	// private static BeidanHistoryLotteryInfoCommunicater beidanCommunicater;
	// private static ExpectListCommunicater expectListCommunicater;
	// private static BasketballHistoryLotteryInfoCommunicater
	// basketballCommunicater;

	private ArrayList<Hashtable<String, String>> groupContent;
	private ArrayList<ArrayList<Hashtable<String, String>>> childContent;
	private ArrayList<View> groupContentView;
	private ArrayList<ArrayList<View>> childContentView;
	private static String serverMessage = "";
	// message
	private static final int GET_FOOTBALL_LOTTERYINFO_SUCCEED = 1001;
//	private static final int GET_FOOTBALL_LOTTERYINFO_FAILED = 1002;
//	private static final int GET_BEIDAN_LOTTERYINFO_SUCCEED = 1003;
//	private static final int GET_BEIDAN_LOTTERYINFO_FAILED = 1004;
//	private static final int GET_EXPECTLIST_LOTTERYINFO_SUCCEED = 1005;
//	private static final int GET_EXPECTLIST_LOTTERYINFO_FAILED = 1006;
	public static final int DATE_CHANGED = 1007;
	public static final int EXPECT_CHANGED = 1008;
//	private static final int GET_BASKETBALL_LOTTERYINFO_SUCCEED = 1009;
//	private static final int GET_BASKETBALL_LOTTERYINFO_FAILED = 1010;
	private int shoudClosedGroup;
	private ProgressDialog progressDialog;

	private boolean isShow = true;// 是否显示提示框
	/** 北单期号获取是否成功 */
	public static boolean isGetExpectSucceed = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lotteryinfo_list_football);

		initHandler();
		initUI();
	}

	private void initUI() {

		progressDialog = ViewerUtil.showProgressDialog(this, "加载中...");
		progressDialog.show();

		communicater = new FootballLotteryInfoCommunicater(handler);
		communicater.startCommunicate();
		// beidanCommunicater = new BeidanHistoryLotteryInfoCommunicater();
		// expectListCommunicater = new ExpectListCommunicater();
		// basketballCommunicater = new
		// BasketballHistoryLotteryInfoCommunicater();

//		bundle = this.getIntent().getExtras();
		// lotid = bundle.getString("lotid");
		lotid = Config.JINGCAIZUQIU;

		tvFail = (TextView) findViewById(R.id.lotteryinfo_list_football_tv_fail);
		tvTipDate = (TextView) findViewById(R.id.lotteryinfo_list_football_tv_dateTip);
		tvTipWeek = (TextView) findViewById(R.id.lotteryinfo_list_football_tv_weekTip);
		tvTipCount = (TextView) findViewById(R.id.lotteryinfo_list_football_tv_countTip);

		backbtnButton = (Button) findViewById(R.id.sportteryfootballagp_btn_cancel);
		backbtnButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				LotteryInfoListFootball.this.finish();
			}
		});

		relativeTipTop = (RelativeLayout) findViewById(R.id.lotteryinfo_list_football_linear_dateTip);
		relativeTipTop.setOnClickListener(this);
		imgTipTop = (ImageView) findViewById(R.id.lotteryinfo_list_football_img);

		groupContent = new ArrayList<Hashtable<String, String>>();
		childContent = new ArrayList<ArrayList<Hashtable<String, String>>>();
		groupContentView = new ArrayList<View>();
		childContentView = new ArrayList<ArrayList<View>>();

		expandListView = (ExpandableListView) findViewById(R.id.lotteryinfo_list_football_act_expandlist_football);
		expandListAdapter = new LotteryInfoExpendsAdapter(
				LotteryInfoListFootball.this, groupContent, groupContentView,
				childContent, childContentView, lotid);
		expandListView.setAdapter(expandListAdapter);
		expandListView.setOnScrollListener(this);
		if (lotid.equals(Config.JINGCAIZUQIU)) {
			relativeTipTop.setBackgroundResource(R.drawable.bg_default_date);
			tvTipDate.setTextColor(getResources().getColor(R.color.white));
			tvTipWeek.setTextColor(getResources().getColor(R.color.white));
			tvTipCount.setTextColor(getResources().getColor(R.color.white));
			// getLotteryInfoThread("0");
		}
		// else if (lotid.equals(Config.BEIJINGZUQIUDANCHANG)) {
		// relativeTipTop.setBackgroundResource(R.drawable.btn_kjxx_group_style);
		// tvTipDate.setTextColor(getResources().getColor(R.color.white));
		// tvTipWeek.setTextColor(getResources().getColor(R.color.white));
		// tvTipCount.setTextColor(getResources().getColor(R.color.white));
		// getExpectListThread(lotid, "34", "0");
		// }
		// else if (lotid.equals(Config.JINGCAILANQIU)) {
		// relativeTipTop.setBackgroundResource(R.drawable.btn_kjxx_basketball_style);
		// tvTipDate.setTextColor(getResources().getColor(R.color.solid_black));
		// tvTipWeek.setTextColor(getResources().getColor(R.color.solid_black));
		// tvTipCount.setTextColor(getResources().getColor(R.color.solid_black));
		// getBasketballLotteryInfoThread("0");
		// }
	}

	// private void initHandler() {
	//
	// handler = new Handler() {
	//
	// @Override
	// public void handleMessage(Message msg) {
	// super.handleMessage(msg);
	// switch (msg.what) {
	// case Config.COMMUNICATER_SUCCESS:
	// if (null == shareUserName && null == shareUserpass) {
	// saveSharedPreferences();
	// } else {
	// saveUsedSharedPreferences();
	//
	// }
	//
	// saveUserInfo();
	// gotoLoggedinAct();
	// if (progressDialog.isShowing()) {
	// progressDialog.cancel();
	// }
	// closeDialog();
	// break;
	// case Config.COMMUNICATER_FAIL:
	// ViewerUtil.showTipDialog(getParent(),
	// personallogincommunicater.getServerMsg(), false);
	// if (progressDialog.isShowing()) {
	// progressDialog.cancel();
	// }
	// closeDialog();
	// setContentView(R.layout.login);
	// uiInit();
	// break;
	// case Config.COMMUNICATER_EXCEPTION:
	// ViewerUtil.showTipDialog(getParent(),
	// Language.NERWORK_ABORT, false);
	// if (progressDialog.isShowing()) {
	// progressDialog.cancel();
	// }
	// EDebug.o("通讯异常" + UserInfo.getUserInfo().getFreezemoney());
	// closeDialog();
	// setContentView(R.layout.login);
	// uiInit();
	// break;
	// }
	// }
	// };
	// }
	// 消息处理
	private void initHandler() {
		handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				super.handleMessage(msg);
				switch (msg.what) {
				case Config.COMMUNICATER_SUCCESS:

					communicateSucceed(
							communicater.getFootballLotteryInfoList(),
							communicater.getCountList(),
							communicater.getWeekList(),
							communicater.getDateList());
					if (progressDialog != null) {
						progressDialog.cancel();
					}

					break;

				case Config.COMMUNICATER_FAIL:

					if (communicater.getState() == 202) {
						if (isShow) {
//							ViewerUtil.showTipDialog(
//									LotteryInfoListFootball.this,
//									serverMessage, false);
							Toast.makeText(LotteryInfoListFootball.this,
									serverMessage, 500)
									.show();
						}
						tvFail.setVisibility(View.VISIBLE);
					}
					if (progressDialog != null) {
						progressDialog.cancel();
					}
					if (groupContent.size() != 0) {
					}
					break;

				case Config.COMMUNICATER_EXCEPTION:

					if (isShow) {
//						ViewerUtil.showTipDialog(LotteryInfoListFootball.this,
//								Language.STR_CONNECTIONFAIL, false);
						Toast.makeText(LotteryInfoListFootball.this,
								Language.STR_CONNECTIONFAIL, 500)
								.show();
					}
					if (progressDialog != null) {
						progressDialog.cancel();
					}
					break;

				case DATE_CHANGED:
					//
					Hashtable<String, String> map = new Hashtable<String, String>();
//					map = (Hashtable<String, String>) msg.obj;
					progressDialog.show();
					// if (lotid.equals(Config.JINGCAILANQIU)) {
					//
					// getBasketballLotteryInfoThread(map.get("year") + "-" +
					// map.get("month") + "-" + map.get("day"));
					// } else if (lotid.equals(Config.JINGCAIZUQIU)) {
					//
					getLotteryInfoThread(map.get("year") + "-"
							+ map.get("month") + "-" + map.get("day"));
					// }
					//
					break;

				/*
				 * case GET_BEIDAN_LOTTERYINFO_SUCCEED:
				 * 
				 * isGetExpectSucceed = true;
				 * displayBeiDanInfo(beidanCommunicater.getBeidanLotteryInfo());
				 * if (progressDialog != null) { progressDialog.cancel(); }
				 * 
				 * break;
				 * 
				 * case GET_BEIDAN_LOTTERYINFO_FAILED:
				 * 
				 * if (isShow) {
				 * ViewerUtil.showTipDialog(LotteryInfoListFootball.this,
				 * beidanCommunicater.getServerMsg(), false); } if
				 * (progressDialog != null) { progressDialog.cancel(); }
				 * 
				 * break;
				 */

				/*
				 * case GET_EXPECTLIST_LOTTERYINFO_SUCCEED:
				 * 
				 * expectListCommunicater.updateExpecList(); expectSelected =
				 * ExpectListInfo.getExpectListInfo().getExpectList().get(1);
				 * getBeidanLotteryInfoThread(expectSelected);
				 * 
				 * break;
				 */

				/*
				 * case GET_EXPECTLIST_LOTTERYINFO_FAILED:
				 * 
				 * if (isShow) {
				 * ViewerUtil.showTipDialog(LotteryInfoListFootball.this,
				 * expectListCommunicater.getServerMsg(), false); } if
				 * (progressDialog != null) { progressDialog.cancel(); }
				 * 
				 * break;
				 */
				/*
				 * case EXPECT_CHANGED:
				 * 
				 * progressDialog.show(); expectSelected = (String) msg.obj;
				 * getBeidanLotteryInfoThread(expectSelected);
				 * 
				 * break;
				 * 
				 * case GET_BASKETBALL_LOTTERYINFO_SUCCEED:
				 * 
				 * communicateSucceed(basketballCommunicater.
				 * getBasketballLotteryInfoList(),
				 * basketballCommunicater.getCountList(),
				 * basketballCommunicater.getWeekList(),
				 * basketballCommunicater.getDateList()); if (progressDialog !=
				 * null) { progressDialog.cancel(); }
				 * 
				 * break;
				 * 
				 * case GET_BASKETBALL_LOTTERYINFO_FAILED:
				 * 
				 * if (basketballCommunicater.getState() == 202) { if (isShow) {
				 * ViewerUtil.showTipDialog(LotteryInfoListFootball.this,
				 * serverMessage, false); } tvFail.setVisibility(View.VISIBLE);
				 * } if (progressDialog != null) { progressDialog.cancel(); } if
				 * (groupContent.size() != 0) { } break;
				 */

				default:
					break;
				}
			}
		};
	}

	// 获取竞彩足球开奖信息
	private static void getLotteryInfoThread(final String date) {
		new Thread() {

			@Override
			public void run() {
				super.run();
				Message msg = new Message();
				try {
					// boolean isSucceed =
					// communicater.isGetFootballLotteryInfo(date);
					// serverMessage = communicater.getServerMsg();
					// EDebug.o("---------------", communicater.getErrorMSG());
					// if (isSucceed) {
					msg = handler.obtainMessage(
							GET_FOOTBALL_LOTTERYINFO_SUCCEED, null);
					// } else {
					// msg =
					// handler.obtainMessage(GET_FOOTBALL_LOTTERYINFO_FAILED,
					// null);
					// }
					handler.sendMessage(msg);
				} catch (Exception e) {
					msg = handler.obtainMessage(Config.CONNECTION_FAIL, null);
					handler.sendMessage(msg);
				}
			}
		}.start();
	}

	// 获取竞彩篮球开奖信息
	/*
	 * private static void getBasketballLotteryInfoThread(final String date) {
	 * new Thread() {
	 * 
	 * @Override public void run() { super.run(); Message msg = new Message();
	 * try { boolean isSucceed =
	 * basketballCommunicater.isGetBasketballLotteryInfo(date); serverMessage =
	 * basketballCommunicater.getServerMsg(); EDebug.o("---------------",
	 * basketballCommunicater.getErrorMSG()); if (isSucceed) { msg =
	 * handler.obtainMessage(GET_BASKETBALL_LOTTERYINFO_SUCCEED, null); } else {
	 * msg = handler.obtainMessage(GET_BASKETBALL_LOTTERYINFO_FAILED, null); }
	 * handler.sendMessage(msg); } catch (Exception e) { msg =
	 * handler.obtainMessage(Config.CONNECTION_FAIL, null);
	 * handler.sendMessage(msg); } } }.start(); }
	 */

	// 获取北京单场开奖信息
	/*
	 * private static void getBeidanLotteryInfoThread(final String expect) { new
	 * Thread() {
	 * 
	 * @Override public void run() { super.run(); Message msg = new Message();
	 * try { boolean isSucceed =
	 * beidanCommunicater.isGetLotteryInfoSucceed(expect); serverMessage =
	 * beidanCommunicater.getServerMsg(); EDebug.o("---------------",
	 * beidanCommunicater.getErrorMSG()); if (isSucceed) { msg =
	 * handler.obtainMessage(GET_BEIDAN_LOTTERYINFO_SUCCEED, null); } else { msg
	 * = handler.obtainMessage(GET_BEIDAN_LOTTERYINFO_FAILED, null); }
	 * handler.sendMessage(msg); } catch (Exception e) { msg =
	 * handler.obtainMessage(Config.CONNECTION_FAIL, null);
	 * handler.sendMessage(msg); } } }.start(); }
	 */

	// 获取北京单场期号列表
	/*
	 * private static void getExpectListThread(final String lotid, final String
	 * playid, final String type) { new Thread() {
	 * 
	 * @Override public void run() { super.run(); Message msg = new Message();
	 * try { boolean isSucceed =
	 * expectListCommunicater.isGetExpectListSucceed(lotid, playid, type);
	 * serverMessage = expectListCommunicater.getServerMsg();
	 * EDebug.o("---------------", expectListCommunicater.getErrorMSG()); if
	 * (isSucceed) { msg =
	 * handler.obtainMessage(GET_EXPECTLIST_LOTTERYINFO_SUCCEED, null); } else {
	 * msg = handler.obtainMessage(GET_EXPECTLIST_LOTTERYINFO_FAILED, null); }
	 * handler.sendMessage(msg); } catch (Exception e) { msg =
	 * handler.obtainMessage(Config.CONNECTION_FAIL, null);
	 * handler.sendMessage(msg); } } }.start(); }
	 */

	private void communicateSucceed(
			ArrayList<FootballLotteryInfoListInfo> list, String count_List,
			String week_List, String date_List) {

		String[] dayList = date_List.split(",");
		String[] weekList = week_List.split(",");

		String[] countList = count_List.split(",");

		int first = Integer.valueOf(countList[0]);
		int second = Integer.valueOf(countList[1]);
		int third = Integer.valueOf(countList[2]);

		// 清除以前数据
		clearListDate();
		// 对开奖信息列表按照日期分组排序
		sortListInfo(list);
		// 确定group
		for (int i = 0; i < dayList.length; i++) {
			// EDebug.o("---------------", "加第" + i + "个日期分割item" + dayList[i]);
			// Hashtable<String, String> mapTitle = new Hashtable<String,
			// String>();
			// mapTitle.put("istitle", "yes");
			// mapTitle.put("date", dayList[i]);
			// mapTitle.put("week", weekList[i]);
			// mapTitle.put("count", countList[i]);
			//
			// groupContent.add(mapTitle);
			ArrayList<Hashtable<String, String>> childTemp = new ArrayList<Hashtable<String, String>>();
			childContent.add(childTemp);
			ArrayList<View> childViewTemp = new ArrayList<View>();
			childContentView.add(childViewTemp);
		}
		// 添加child
		for (int i = 0; i < list.size(); i++) {

			String[] strScore = list.get(i).getScore().split(":");
			if (strScore[0].equals("-1") || strScore[1].equals("-1")) {
				EDebug.o("---------------", "比分为" + list.get(i).getScore()
						+ "滤掉");
				if (list.get(i).getMatchNumDate().equals(dayList[0])) {
					first--;
				} else if (list.get(i).getMatchNumDate().equals(dayList[1])) {
					second--;
				} else if (list.get(i).getMatchNumDate().equals(dayList[2])) {
					third--;
				}
			} else {
				if (list.get(i).getMatchNumDate().equals("")
						|| list.get(i).getHomeTeam().equals("")
						|| list.get(i).getVisitingTeam().equals("")) {
					EDebug.o("---------------", "日期，队名为空====滤掉");
					if (list.get(i).getMatchNumDate().equals(dayList[0])) {
						first--;
					} else if (list.get(i).getMatchNumDate().equals(dayList[1])) {
						second--;
					} else if (list.get(i).getMatchNumDate().equals(dayList[2])) {
						third--;
					}
				} else {
					EDebug.o("---------------", "正确的队伍信息");
					int groupPos = 0;
					EDebug.o("---------------", "daylist.length = "
							+ dayList.length + dayList[0]);
					for (int j = 0; j < dayList.length; j++) {
						if (list.get(i).getMatchNumDate().equals(dayList[j])) {
							groupPos = j;
							break;
						}
					}
					EDebug.o("---------------", "添加child" + groupPos + "==" + i);
					Hashtable<String, String> mapList = new Hashtable<String, String>();
					mapList.put("istitle", "no");
					mapList.put("matchnum", list.get(i).getMatchNum());
					mapList.put("date", list.get(i).getMatchNumDate());
					mapList.put("hometeam", list.get(i).getHomeTeam());

					mapList.put("resultspf", list.get(i).getResultspf());
					mapList.put("homescore", list.get(i).getHomescore());
					mapList.put("awayscore", list.get(i).getAwayscore());
					mapList.put("homestanding", list.get(i).getHomestanding());
					mapList.put("awaystanding", list.get(i).getAwaystanding());
					// if (!lotid.equals(Config.JINGCAILANQIU)) {
					mapList.put("rangqiu", list.get(i).getRangQiu());
					// }
					mapList.put("visitingteam", list.get(i).getVisitingTeam());
					mapList.put("score",
							list.get(i).getScore().replace(":", "-"));
					if (list.get(i).getState().equals("2")) {
						mapList.put("result", "(胜)");
					} else if (list.get(i).getState().equals("1")) {
						mapList.put("result", "(平)");
					} else if (list.get(i).getState().equals("0")) {
						mapList.put("result", "(负)");
					}
					mapList.put("leaguename", list.get(i).getSipleLeague());
					// mapList.put("hometeam_img",
					// list.get(i).getHomeTeamImage());
					// mapList.put("visit_img",
					// list.get(i).getVisitTeamImage());

					childContent.get(groupPos).add(mapList);
				}
			}
		}
		EDebug.o("---------------", countList[0] + "***" + countList[1] + "***"
				+ countList[2] + "***" + first + "***" + second + "***" + third
				+ "***");
		// 确定group
		for (int i = 0; i < dayList.length; i++) {
			EDebug.o("---------------", "加第" + i + "个日期分割item" + dayList[i]);
			Hashtable<String, String> mapTitle = new Hashtable<String, String>();
			mapTitle.put("istitle", "yes");
			mapTitle.put("date", dayList[i]);
			mapTitle.put("week", weekList[i]);
			if (i == 0) {
				mapTitle.put("count", String.valueOf(first));
			} else if (i == 1) {
				mapTitle.put("count", String.valueOf(second));
			} else if (i == 2) {
				mapTitle.put("count", String.valueOf(third));
			}

			groupContent.add(mapTitle);
			// ArrayList<Hashtable<String, String>> childTemp = new
			// ArrayList<Hashtable<String, String>>();
			// childContent.add(childTemp);
			// ArrayList<View> childViewTemp = new ArrayList<View>();
			// childContentView.add(childViewTemp);
		}
		expandListAdapter.notifyDataSetChanged();
		// 展开所有组
		for (int i = 0; i < groupContent.size(); i++) {
			expandListView.expandGroup(i);
		}

		expandListView.setSelection(0);
	}

	// 清除数据
	private void clearListDate() {

		groupContent.clear();
		groupContentView.clear();
		childContent.clear();
		childContentView.clear();

	}

	// 页面暂停时不显示提示
	@Override
	protected void onPause() {
		super.onPause();
		isShow = false;
		if (expandListAdapter.isCacheUtilNull()) {
			EDebug.o("---------------", "null");
		} else {
			expandListAdapter.stopImageThread();
		}
		this.unregisterReceiver(ConnectionChangeReceiver
				.getConnectionChangeReceiver());
	}

	// 页面恢复时可以显示提示
	@Override
	protected void onResume() {
		super.onResume();
		isShow = true;
		this.registerReceiver(
				ConnectionChangeReceiver.getConnectionChangeReceiver(),
				ConnectionChangeReceiver.getIntentFilter());
	}

	// 更新date tip bar数据
	private void updteTipBar(String date, String week, String count) {

		tvTipDate.setText(date);
		tvTipWeek.setText(week);
		tvTipCount.setText(count + "场比赛已截止");

	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {

		ExpandableListView listView = (ExpandableListView) view;
		int npos = view.pointToPosition(0, 0);
		if (npos != AdapterView.INVALID_POSITION) {
			long pos = listView.getExpandableListPosition(npos);
			int childPos = ExpandableListView.getPackedPositionChild(pos);
			int groupPos = ExpandableListView.getPackedPositionGroup(pos);
			shoudClosedGroup = groupPos;
			EDebug.o("---------------", "group =" + groupPos + "===child ="
					+ childPos);
			if (childPos >= 0) {
				if (childPos == childContent.get(groupPos).size() - 1) {
					if (groupPos < groupContent.size() - 1) {
						groupPos++;
						shoudClosedGroup = groupPos;
					}
				}
				if (relativeTipTop.getVisibility() != View.VISIBLE) {
					relativeTipTop.setAnimation(AnimationUtils.loadAnimation(
							this, android.R.anim.fade_in));
					relativeTipTop.setVisibility(View.VISIBLE);
					imgTipTop.setBackgroundDrawable(getResources().getDrawable(
							R.drawable.icon_default_packup));
				}
				EDebug.o("---------------",
						"group position = <<<<<" + groupPos + ">>>>>"
								+ "count =<<<<<<<<"
								+ groupContent.get(groupPos).get("count")
								+ ">>>>>>>>>>>>");
				updteTipBar(groupContent.get(groupPos).get("date"),
						groupContent.get(groupPos).get("week"), groupContent
								.get(groupPos).get("count"));
			} else if (childPos == -1) {
				if (groupPos < groupContent.size()) {
					updteTipBar(groupContent.get(groupPos).get("date"),
							groupContent.get(groupPos).get("week"),
							groupContent.get(groupPos).get("count"));
					EDebug.o("---------------", "count ============<<<<<<<"
							+ groupContent.get(groupPos).get("count")
							+ ">>>>>>>>>>>>");
					if (relativeTipTop.getVisibility() == View.VISIBLE) {
						relativeTipTop.setAnimation(AnimationUtils
								.loadAnimation(this, android.R.anim.fade_out));
						relativeTipTop.setVisibility(View.GONE);
					}
				} else {
					EDebug.o("---------------", "group =" + groupPos);
				}
			}
		}
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
	}

	@Override
	public void onClick(View v) {
		if (shoudClosedGroup < groupContent.size()) {
			expandListView.collapseGroup(shoudClosedGroup);
			expandListView.setSelectedGroup(shoudClosedGroup);
			imgTipTop.setBackgroundDrawable(getResources().getDrawable(
					R.drawable.icon_default_unfold));
		} else {
			EDebug.o("---------------", "shouldColsedGroup = "
					+ shoudClosedGroup);
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_MENU
				|| keyCode == KeyEvent.KEYCODE_DPAD_LEFT
				|| keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
			Activity parent = getParent();
			if (parent != null) {
				parent.onKeyDown(keyCode, event);
				return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	public boolean onTrackballEvent(MotionEvent event) {
		Activity parent = getParent();
		if (parent != null) {
			parent.onTrackballEvent(event);
			return true;
		}
		return false;
	}

	// 北单数据显示
	@SuppressWarnings("unused")
	private void displayBeiDanInfo(ArrayList<FootballLotteryInfoListInfo> list) {

		clearListDate();
		// 开奖信息列表按时间分组排序
		sortListInfo(list);

		int groupPos = -1;
		ArrayList<String> dateList = new ArrayList<String>();
		ArrayList<String> weekList = new ArrayList<String>();
		// 添加child
		EDebug.o("---------------", "state size = " + list.size());
		EDebug.o("---------------", "match num date size = " + list.size());
		for (int i = 0; i < list.size(); i++) {

			if (i == 0
					|| !list.get(i).getMatchNumDate()
							.equals(list.get(i - 1).getMatchNumDate())) {

				ArrayList<Hashtable<String, String>> childTemp = new ArrayList<Hashtable<String, String>>();
				childContent.add(childTemp);
				ArrayList<View> childViewTemp = new ArrayList<View>();
				childContentView.add(childViewTemp);

				groupPos++;
				dateList.add(list.get(i).getMatchNumDate());
				weekList.add(list.get(i).getDayOfWeek());
				EDebug.o("---------------", "date list="
						+ list.get(i).getMatchNumDate());
			}

			String[] strScore = list.get(i).getScore().split(":");
			if (strScore[0].equals("-1") || strScore[1].equals("-1")) {

				EDebug.o("---------------", "比分为" + list.get(i).getScore()
						+ "滤掉");

			} else if (list.get(i).getMatchNumDate().equals("")
					|| list.get(i).getHomeTeam().equals("")
					|| list.get(i).getVisitingTeam().equals("")) {

				EDebug.o("---------------", "日期，队名为空====滤掉");

			} else {

				EDebug.o("---------------", "正确的队伍信息");
				EDebug.o("---------------", "添加child" + groupPos + "==" + i);
				Hashtable<String, String> mapList = new Hashtable<String, String>();
				mapList.put("istitle", "no");
				mapList.put("matchnum", list.get(i).getMatchNum());
				mapList.put("date", list.get(i).getMatchNumDate());
				mapList.put("hometeam", list.get(i).getHomeTeam());
				mapList.put("rangqiu", list.get(i).getRangQiu());
				mapList.put("visitingteam", list.get(i).getVisitingTeam());
				mapList.put("score", list.get(i).getScore().replace(":", "-"));
				if (list.get(i).getState().equals("2")) {
					mapList.put("result", "(胜)");
				} else if (list.get(i).getState().equals("1")) {
					mapList.put("result", "(平)");
				} else if (list.get(i).getState().equals("0")) {
					mapList.put("result", "(负)");
				}
				mapList.put("leaguename", list.get(i).getSipleLeague());
				// mapList.put("hometeam_img", list.get(i).getHomeTeamImage());
				// mapList.put("visit_img", list.get(i).getVisitTeamImage());

				childContent.get(groupPos).add(mapList);
			}
		}

		// 确定group
		for (int i = 0; i < groupPos + 1; i++) {
			EDebug.o("---------------", "加第" + i + "个日期分割item");
			Hashtable<String, String> mapTitle = new Hashtable<String, String>();
			mapTitle.put("istitle", "yes");
			mapTitle.put("date", dateList.get(i));
			mapTitle.put("week", "第" + expectSelected + "期");
			mapTitle.put("count", String.valueOf(childContent.get(i).size()));
			groupContent.add(mapTitle);
		}
		expandListAdapter.notifyDataSetChanged();
		// 展开所有组
		for (int i = 0; i < groupContent.size(); i++) {
			expandListView.expandGroup(i);
		}

		expandListView.setSelection(0);

	}

	/**
	 * @Title: sortListInfo
	 * @Description: (对返回列表进行日期排序)
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void sortListInfo(ArrayList<FootballLotteryInfoListInfo> listInfo) {
		Collections.sort(listInfo, new Comparator() {
			@Override
			public int compare(Object object1, Object object2) {
				FootballLotteryInfoListInfo sa1 = (FootballLotteryInfoListInfo) object1;
				FootballLotteryInfoListInfo sa2 = (FootballLotteryInfoListInfo) object2;
				int i = (sa1.getMatchNumDate()).compareTo(sa2.getMatchNumDate());
				return i;
			}
		});

	}
}
